from libavg import avg
from libavg.ui.button import TouchButton
import Constants

class Help(avg.DivNode):
    
    __BTN_SIZE = avg.Point2D(255, 88)
    
    def __init__(self, parent, game, **kwargs):
        super(Help, self).__init__(**kwargs)

        self.__game = game
        
        if parent:
            parent.appendChild(self)
        
        self.size = Constants.RESOLUTION 
        self.imgBgr = avg.ImageNode(parent=self, href="resources/textures/help/bgr.png", size=self.size)  
        self.imgContent = avg.ImageNode(parent=self, href="resources/textures/help/items.png", size=self.size)      
       
        self.__closeBtn = TouchButton (
                parent = self,
                pos = (Constants.RESOLUTION.x - 60, Constants.RESOLUTION.y - 50 - 10),
                size=(50,50),
                upNode = avg.ImageNode(href = "resources/textures/menu/btn_exit.png", size=(50, 50)),
                downNode = avg.ImageNode(href = "resources/textures/menu/btn_exit_d.png", size=(50, 50)),
                clickHandler = lambda: self.__game.showMenu()) 
        
        self.__itemsBtn = TouchButton (
                parent = self,
                pos = (200, Constants.RESOLUTION.y - self.__BTN_SIZE.y - 30),
                size = self.__BTN_SIZE,
                upNode = avg.ImageNode(href = "resources/textures/help/btn_item.png", size=self.__BTN_SIZE),
                downNode = avg.ImageNode(href = "resources/textures/help/btn_item_d.png", size=self.__BTN_SIZE),
                clickHandler = lambda: self.__changeContent("items"))
        
        self.__controlsBtn = TouchButton (
                parent = self,
                pos = (500, Constants.RESOLUTION.y - self.__BTN_SIZE.y - 30),
                size = self.__BTN_SIZE,
                upNode = avg.ImageNode(href = "resources/textures/help/btn_controls.png", size=self.__BTN_SIZE),
                downNode = avg.ImageNode(href = "resources/textures/help/btn_controls_d.png", size=self.__BTN_SIZE),
                clickHandler = lambda: self.__changeContent("controls"))
        
        self.__rulesBtn = TouchButton (
                parent = self,
                pos = (800, Constants.RESOLUTION.y - self.__BTN_SIZE.y - 30),
                size = self.__BTN_SIZE,
                upNode = avg.ImageNode(href = "resources/textures/help/btn_rules.png", size=self.__BTN_SIZE),
                downNode = avg.ImageNode(href = "resources/textures/help/btn_rules_d.png", size=self.__BTN_SIZE),
                clickHandler = lambda: self.__changeContent("rules"))
        
    def __changeContent(self, newVal):
        if newVal is not None:
            self.imgContent.href = "resources/textures/help/"+newVal+".png"
        else:
            self.imgContent.href = ""